from sqlalchemy import Column, Integer, String, DateTime, BIGINT, Float

from src.config.database import Base


class HiDolphinQaData(Base):
    __tablename__: str = "hi_dolphin_qa_data"
    __table_args__ = {"schema": "public"}
    id = Column(String, primary_key=True)
    user_id = Column(String, unique=True, index=True)
    project_id = Column(String)
    query = Column(String)
    answer = Column(String)
    input_tokens = Column(Integer)
    output_tokens = Column(Integer)
    total_tokens = Column(Integer)
    timestamp = Column(DateTime)
    resolved = Column(Integer)

    def to_dict(self):
        return {
            c.name: getattr(self, c.name) for c in self.__table__.columns
        }


class VvvUserLoginLog(Base):
    __tablename__: str = "vvv_user_login_log"
    __table_args__ = {"schema": "public"}
    id = Column(String, primary_key=True)
    company_type = Column(String)
    user_id = Column(String, unique=True, index=True)
    register_channel = Column(String)
    register_time = Column(DateTime)
    channel_client = Column(String)
    login_type = Column(Integer)
    login_time = Column(DateTime)
    resolved = Column(Integer)

    def to_dict(self):
        return {
            c.name: getattr(self, c.name) for c in self.__table__.columns
        }


class VvvApiCallRecord(Base):
    __tablename__: str = "vvv_api_call_record"
    __table_args__ = {"schema": "public"}
    id = Column(String, primary_key=True)
    company_type = Column(String)
    user_id = Column(String, unique=True, index=True)
    access_date = Column(DateTime)
    access_times = Column(Integer)
    api_name = Column(String)
    resolved = Column(Integer)

    def to_dict(self):
        return {
            c.name: getattr(self, c.name) for c in self.__table__.columns
        }


class Label(Base):
    __tablename__: str = "label"
    __table_args__ = {"schema": "public"}
    id = Column(String, primary_key=True)
    label_code = Column(String)
    label_name = Column(String)
    label_desc = Column(String)
    parent_label_id = Column(String)
    label_type = Column(String)
    label_key = Column(String)


class LabelUser(Base):
    __tablename__: str = "label_user"
    __table_args__ = {"schema": "public"}
    id = Column(String, primary_key=True)
    label_id = Column(String)
    user_id = Column(String)
    label_value = Column(Integer)


class User(Base):
    __tablename__: str = "user"
    __table_args__ = {"schema": "public"}
    id = Column(String, primary_key=True)
    user_name_cn = Column(String)
    company_id = Column(String)
    company_type = Column(String)
    user_id = Column(String, unique=True, index=True)
    liveness = Column(Float)
